<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //1.定义一个交通工具类，该类有载重量属性和行驶方法、停止行驶方法
        function Transport(weight) {
            this.weight = weight;
        }
        Transport.prototype.run = function () {
            console.log('在路上');
        }
        Transport.prototype.stop = function () {
            console.log('已停止');
        }

        //2.定义卡车类，它是交通工具类的子类，子类有自己的品牌属性和装货、卸货方法
        function truck(weight, brand) {
            //子类继承父类属性
            Transport.call(this, weight);
            this.brand = brand;
        }
        //子类继承父类方法
        truck.prototype = new Transport();
        truck.prototype.constructor = truck;
        //子类的装货、卸货方法
        truck.prototype.load = function () {
            console.log('装货');
        }
        truck.prototype.unload = function () {
            console.log('卸货');
        }

        // var T = new Transport(3000);
        // var t = new truck(2000, 'a');


        //创建子类对象
        var t = new truck(20, 'a');
        //设置weight属性不可修改    
        Object.defineProperty(t, 'weight', {
            writable: false,       //不可修改
            // enumerable: false   //不允许遍历
            configurable: false    //不允许删除
        })
        // t.weight = 30;//修改语句失效
        // console.log(t);

        //遍历对象属性和方法  被禁止遍历的不显示
        for (var pro in t) {
            console.log(pro, ':', t[pro])
        }

        //delete 对象名.属性名   删除对象的属性
        //如果该属性不可删除，删除时不报错，删除无效
        delete t.weight;
        //属性删除后，打印该属性，不报错，显示为undefined
        console.log(t.weight);

        //添加属性
        Object.defineProperty(t, 'test', {
            value: '123',
            writable: false,
            configurable: false
        })
        console.log(t);
    </script>
</body>

</html>